<template>
  <li
    @mousemove="isShow = true"
    @mouseleave="isShow = false"
    :class="{ active: isShow }"
  >
    <label>
      <input type="checkbox" :checked="todo.isOver" @click="updataOne" />
      <span>{{ todo.content }}</span>
    </label>
    <button class="btn btn-danger" v-show="isShow" @click="deleteOne">
      删除
    </button>
  </li>
</template>

<script>
export default {
  name: "Item",
  props: ["todo", "updataTodo", "index", "deleteOneTodo"],
  data() {
    return {
      isShow: false,
    };
  },
  methods: {
    // 修改选中按钮的状态
    updataOne() {
      this.updataTodo(this.index);
    },
    // 删除单个按钮
    deleteOne() {
      this.deleteOneTodo(this.index);
    },
  },
};
</script>

<style scoped>
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}
li.active {
  background-color: skyblue;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  /* display: none; */
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>
